package UILayer;
import ControllerLayer.*;
import ModelLayer.*;


import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.BevelBorder;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JCheckBox;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import javax.swing.table.DefaultTableCellRenderer;

public class SalesGUI extends JFrame {

	private JPanel contentPane;
	private JTextField txtCustomerNo;
	private JTextField txtCustomerGroup;
	private JTextField txtFirstName;
	private JTextField txtLastName;
	private JTextField txtCompany;
	private JTextField txtCvrNo;
	private JTextField txtRoad;
	private JTextField txtHouseNo;
	private JTextField txtPostalcode;
	private JTextField txtCity;
	private JTextField txtPhone;
	private JTextField txtEmail;
	private JTable tableDiscount;
	private JTextField txtDeliveryDate;
	private JTextField txtFirstnameDelivery;
	private JTextField txtLastnameDelivery;
	private JTextField txtRoadDelivery;
	private JTextField txtHouseNoDelivery;
	private JTextField txtPostalcodeDelivery;
	private JTextField txtCityDelivery;
	private JTable tableProduct;
	private JTextField txtTotalPrice;
	private JTextField txtTotalDiscountPrice;
	private JTextField txtTotalPriceWithoutVAT;
	private JTextField txtTotalPriceWithVAT;
	private JTextField txtTotalDiscount;
	
	private SalesController salesController;
	private Order order;
	private TableProductTableModel tableModel;
	
	
	private JTextField txtProductQuantity;
	private JTextField txtProductNo;
	private JLabel lblFirstnameDelivery;
	private JLabel lblLastnameDelivery;
	private JLabel lblRoadDelivery;
	private JLabel lblHouseNoDelivery;
	private JLabel lblPostalcodeDelivery;
	private JLabel lblCityDelivery;
	private JCheckBox chckbxOtherDeliveryAddress;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Order o = new Order();
					SalesGUI frame = new SalesGUI(o);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SalesGUI(Order order) {
		this.order = order;
		salesController = new SalesController();
		tableModel = new TableProductTableModel();
		
		PopulateModelLayer p = new PopulateModelLayer();
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1000, 700);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panelCustomer = new JPanel();
		panelCustomer.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
		panelCustomer.setBounds(10, 11, 234, 639);
		contentPane.add(panelCustomer);
		panelCustomer.setLayout(null);
		
		JLabel lblHeaderCustomerInfo = new JLabel("Kundeoplysninger");
		lblHeaderCustomerInfo.setHorizontalAlignment(SwingConstants.LEFT);
		lblHeaderCustomerInfo.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblHeaderCustomerInfo.setBounds(10, 11, 214, 14);
		panelCustomer.add(lblHeaderCustomerInfo);
		
		JLabel lblCustomerNo = new JLabel("Kundenummer");
		lblCustomerNo.setBounds(10, 33, 91, 14);
		panelCustomer.add(lblCustomerNo);
		
		txtCustomerNo = new JTextField();
		txtCustomerNo.setBounds(10, 55, 86, 20);
		panelCustomer.add(txtCustomerNo);
		txtCustomerNo.setColumns(10);
		
		JButton btnSearchCustomerNo = new JButton("S\u00F8g");
		btnSearchCustomerNo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnSearchCustomerNo.setBounds(106, 55, 65, 23);
		panelCustomer.add(btnSearchCustomerNo);
		
		JLabel lblCustomerGroup = new JLabel("Kundegruppe");
		lblCustomerGroup.setBounds(10, 86, 78, 14);
		panelCustomer.add(lblCustomerGroup);
		
		txtCustomerGroup = new JTextField();
		txtCustomerGroup.setBounds(10, 105, 51, 20);
		panelCustomer.add(txtCustomerGroup);
		txtCustomerGroup.setColumns(10);
		
		JLabel lblFirstName = new JLabel("Fornavn");
		lblFirstName.setBounds(10, 136, 65, 14);
		panelCustomer.add(lblFirstName);
		
		txtFirstName = new JTextField();
		txtFirstName.setColumns(10);
		txtFirstName.setBounds(10, 155, 86, 20);
		panelCustomer.add(txtFirstName);
		
		JLabel lblLastName = new JLabel("Efternavn");
		lblLastName.setBounds(106, 136, 86, 14);
		panelCustomer.add(lblLastName);
		
		txtLastName = new JTextField();
		txtLastName.setColumns(10);
		txtLastName.setBounds(106, 155, 86, 20);
		panelCustomer.add(txtLastName);
		
		JLabel lblCompany = new JLabel("Firma");
		lblCompany.setBounds(10, 186, 46, 14);
		panelCustomer.add(lblCompany);
		
		txtCompany = new JTextField();
		txtCompany.setColumns(10);
		txtCompany.setBounds(10, 205, 86, 20);
		panelCustomer.add(txtCompany);
		
		JLabel lblCvrNo = new JLabel("Cvr-nummer");
		lblCvrNo.setBounds(10, 236, 91, 14);
		panelCustomer.add(lblCvrNo);
		
		txtCvrNo = new JTextField();
		txtCvrNo.setColumns(10);
		txtCvrNo.setBounds(10, 255, 86, 20);
		panelCustomer.add(txtCvrNo);
		
		JLabel lblRoad = new JLabel("Vej");
		lblRoad.setBounds(10, 286, 91, 14);
		panelCustomer.add(lblRoad);
		
		txtRoad = new JTextField();
		txtRoad.setColumns(10);
		txtRoad.setBounds(10, 305, 86, 20);
		panelCustomer.add(txtRoad);
		
		JLabel lblHouseNo = new JLabel("Husnummer");
		lblHouseNo.setBounds(106, 286, 91, 14);
		panelCustomer.add(lblHouseNo);
		
		txtHouseNo = new JTextField();
		txtHouseNo.setColumns(10);
		txtHouseNo.setBounds(106, 305, 51, 20);
		panelCustomer.add(txtHouseNo);
		
		JLabel lblPostalcode = new JLabel("Postnummer");
		lblPostalcode.setBounds(10, 336, 91, 14);
		panelCustomer.add(lblPostalcode);
		
		txtPostalcode = new JTextField();
		txtPostalcode.setColumns(10);
		txtPostalcode.setBounds(10, 355, 86, 20);
		panelCustomer.add(txtPostalcode);
		
		JLabel lblCity = new JLabel("By");
		lblCity.setBounds(106, 336, 91, 14);
		panelCustomer.add(lblCity);
		
		txtCity = new JTextField();
		txtCity.setColumns(10);
		txtCity.setBounds(106, 355, 86, 20);
		panelCustomer.add(txtCity);
		
		JLabel lblPhone = new JLabel("Telefon");
		lblPhone.setBounds(10, 386, 91, 14);
		panelCustomer.add(lblPhone);
		
		txtPhone = new JTextField();
		txtPhone.setColumns(10);
		txtPhone.setBounds(10, 405, 86, 20);
		panelCustomer.add(txtPhone);
		
		JLabel lblEmail = new JLabel("E-mail");
		lblEmail.setBounds(10, 436, 91, 14);
		panelCustomer.add(lblEmail);
		
		txtEmail = new JTextField();
		txtEmail.setColumns(10);
		txtEmail.setBounds(10, 455, 86, 20);
		panelCustomer.add(txtEmail);
		
		JScrollPane scrollPaneDiscount = new JScrollPane();
		scrollPaneDiscount.setBounds(10, 511, 214, 83);
		panelCustomer.add(scrollPaneDiscount);
		
		tableDiscount = new JTable();
		tableDiscount.setFillsViewportHeight(true);
		scrollPaneDiscount.setViewportView(tableDiscount);
		
		JLabel lblDiscount = new JLabel("Rabatter");
		lblDiscount.setBounds(10, 486, 91, 14);
		panelCustomer.add(lblDiscount);
		
		JButton btnCancelCustomerChanges = new JButton("Fortryd");
		btnCancelCustomerChanges.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnCancelCustomerChanges.setBounds(124, 605, 100, 23);
		panelCustomer.add(btnCancelCustomerChanges);
		
		JButton btnSaveCustomerChanges = new JButton("Gem");
		btnSaveCustomerChanges.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				saveCustomerChanges();
			}
		});
		btnSaveCustomerChanges.setBounds(10, 605, 100, 23);
		panelCustomer.add(btnSaveCustomerChanges);
		
		JPanel panelDelivery = new JPanel();
		panelDelivery.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
		panelDelivery.setBounds(254, 11, 397, 166);
		contentPane.add(panelDelivery);
		panelDelivery.setLayout(null);
		
		JLabel lblHeaderDeliveyInfo = new JLabel("Leveringsoplysninger");
		lblHeaderDeliveyInfo.setBounds(10, 11, 147, 14);
		lblHeaderDeliveyInfo.setHorizontalAlignment(SwingConstants.LEFT);
		lblHeaderDeliveyInfo.setFont(new Font("Tahoma", Font.BOLD, 11));
		panelDelivery.add(lblHeaderDeliveyInfo);
		
		JCheckBox chckbxDelivery = new JCheckBox("Levering");
		chckbxDelivery.setBounds(10, 32, 97, 23);
		panelDelivery.add(chckbxDelivery);
		
		chckbxOtherDeliveryAddress = new JCheckBox("Anden leveringsaddresse");
		chckbxOtherDeliveryAddress.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent arg0) {
				setOtherDeliveryAddressState();
			}
		});
		chckbxOtherDeliveryAddress.setBounds(10, 58, 181, 23);
		panelDelivery.add(chckbxOtherDeliveryAddress);
		
		txtDeliveryDate = new JTextField();
		txtDeliveryDate.setBounds(10, 113, 101, 20);
		panelDelivery.add(txtDeliveryDate);
		txtDeliveryDate.setColumns(10);
		
		JLabel lblDeliveyDate = new JLabel("Dato for levering");
		lblDeliveyDate.setBounds(10, 88, 101, 14);
		panelDelivery.add(lblDeliveyDate);
		
		lblFirstnameDelivery = new JLabel("Fornavn");
		lblFirstnameDelivery.setEnabled(false);
		lblFirstnameDelivery.setBounds(195, 11, 65, 14);
		panelDelivery.add(lblFirstnameDelivery);
		
		lblLastnameDelivery = new JLabel("Efternavn");
		lblLastnameDelivery.setEnabled(false);
		lblLastnameDelivery.setBounds(291, 11, 86, 14);
		panelDelivery.add(lblLastnameDelivery);
		
		txtFirstnameDelivery = new JTextField();
		txtFirstnameDelivery.setEnabled(false);
		txtFirstnameDelivery.setColumns(10);
		txtFirstnameDelivery.setBounds(195, 33, 86, 20);
		panelDelivery.add(txtFirstnameDelivery);
		
		txtLastnameDelivery = new JTextField();
		txtLastnameDelivery.setEnabled(false);
		txtLastnameDelivery.setColumns(10);
		txtLastnameDelivery.setBounds(291, 33, 86, 20);
		panelDelivery.add(txtLastnameDelivery);
		
		lblRoadDelivery = new JLabel("Vej");
		lblRoadDelivery.setEnabled(false);
		lblRoadDelivery.setBounds(195, 64, 91, 14);
		panelDelivery.add(lblRoadDelivery);
		
		lblHouseNoDelivery = new JLabel("Husnummer");
		lblHouseNoDelivery.setEnabled(false);
		lblHouseNoDelivery.setBounds(291, 62, 91, 14);
		panelDelivery.add(lblHouseNoDelivery);
		
		txtRoadDelivery = new JTextField();
		txtRoadDelivery.setEnabled(false);
		txtRoadDelivery.setColumns(10);
		txtRoadDelivery.setBounds(195, 86, 86, 20);
		panelDelivery.add(txtRoadDelivery);
		
		txtHouseNoDelivery = new JTextField();
		txtHouseNoDelivery.setEnabled(false);
		txtHouseNoDelivery.setColumns(10);
		txtHouseNoDelivery.setBounds(291, 86, 51, 20);
		panelDelivery.add(txtHouseNoDelivery);
		
		lblPostalcodeDelivery = new JLabel("Postnummer");
		lblPostalcodeDelivery.setEnabled(false);
		lblPostalcodeDelivery.setBounds(195, 114, 91, 14);
		panelDelivery.add(lblPostalcodeDelivery);
		
		lblCityDelivery = new JLabel("By");
		lblCityDelivery.setEnabled(false);
		lblCityDelivery.setBounds(291, 114, 91, 14);
		panelDelivery.add(lblCityDelivery);
		
		txtPostalcodeDelivery = new JTextField();
		txtPostalcodeDelivery.setEnabled(false);
		txtPostalcodeDelivery.setColumns(10);
		txtPostalcodeDelivery.setBounds(195, 136, 86, 20);
		panelDelivery.add(txtPostalcodeDelivery);
		
		txtCityDelivery = new JTextField();
		txtCityDelivery.setEnabled(false);
		txtCityDelivery.setColumns(10);
		txtCityDelivery.setBounds(291, 136, 86, 20);
		panelDelivery.add(txtCityDelivery);
		
		JPanel panelProduct = new JPanel();
		panelProduct.setBounds(254, 188, 720, 408);
		contentPane.add(panelProduct);
		panelProduct.setLayout(null);
		
		JLabel lblHeaderProductInfo = new JLabel("Varer");
		lblHeaderProductInfo.setBounds(10, 25, 121, 14);
		lblHeaderProductInfo.setHorizontalAlignment(SwingConstants.LEFT);
		lblHeaderProductInfo.setFont(new Font("Tahoma", Font.BOLD, 11));
		panelProduct.add(lblHeaderProductInfo);
		
		JScrollPane scrollPaneProduct = new JScrollPane();
		scrollPaneProduct.setBounds(10, 95, 700, 172);
		panelProduct.add(scrollPaneProduct);
		
		tableProduct = new JTable();
		tableProduct.setFillsViewportHeight(true);
		scrollPaneProduct.setViewportView(tableProduct);
		tableProduct.setModel(tableModel);
		DefaultTableCellRenderer rightAlign = new DefaultTableCellRenderer();
		rightAlign.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT);
		tableProduct.getColumnModel().getColumn(2).setCellRenderer(rightAlign);
		tableProduct.getColumnModel().getColumn(3).setCellRenderer(rightAlign);
		tableProduct.getColumnModel().getColumn(5).setCellRenderer(rightAlign);
		
		JButton btnAddProduct = new JButton("Tilf\u00F8j");
		btnAddProduct.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				addPartOrder();
			}
		});
		btnAddProduct.setBounds(162, 63, 68, 23);
		panelProduct.add(btnAddProduct);
		
		JLabel lblTotalPrice = new JLabel("Total");
		lblTotalPrice.setHorizontalAlignment(SwingConstants.RIGHT);
		lblTotalPrice.setBounds(568, 278, 46, 14);
		panelProduct.add(lblTotalPrice);
		
		JLabel lblTotalDiscount = new JLabel("Rabat");
		lblTotalDiscount.setHorizontalAlignment(SwingConstants.RIGHT);
		lblTotalDiscount.setBounds(498, 328, 46, 14);
		panelProduct.add(lblTotalDiscount);
		
		JLabel lblTotalPriceWithoutVAT = new JLabel("Total eks. moms");
		lblTotalPriceWithoutVAT.setHorizontalAlignment(SwingConstants.RIGHT);
		lblTotalPriceWithoutVAT.setBounds(508, 356, 106, 14);
		panelProduct.add(lblTotalPriceWithoutVAT);
		
		JLabel lblTotalPriceWithVAT = new JLabel("Total inkl. moms");
		lblTotalPriceWithVAT.setHorizontalAlignment(SwingConstants.RIGHT);
		lblTotalPriceWithVAT.setBounds(518, 384, 96, 14);
		panelProduct.add(lblTotalPriceWithVAT);
		
		txtTotalPrice = new JTextField();
		txtTotalPrice.setHorizontalAlignment(SwingConstants.RIGHT);
		txtTotalPrice.setBounds(624, 278, 86, 20);
		panelProduct.add(txtTotalPrice);
		txtTotalPrice.setColumns(10);
		
		txtTotalDiscountPrice = new JTextField();
		txtTotalDiscountPrice.setHorizontalAlignment(SwingConstants.RIGHT);
		txtTotalDiscountPrice.setColumns(10);
		txtTotalDiscountPrice.setBounds(624, 325, 86, 20);
		panelProduct.add(txtTotalDiscountPrice);
		
		txtTotalPriceWithoutVAT = new JTextField();
		txtTotalPriceWithoutVAT.setHorizontalAlignment(SwingConstants.RIGHT);
		txtTotalPriceWithoutVAT.setColumns(10);
		txtTotalPriceWithoutVAT.setBounds(624, 353, 86, 20);
		panelProduct.add(txtTotalPriceWithoutVAT);
		
		txtTotalPriceWithVAT = new JTextField();
		txtTotalPriceWithVAT.setHorizontalAlignment(SwingConstants.RIGHT);
		txtTotalPriceWithVAT.setColumns(10);
		txtTotalPriceWithVAT.setBounds(624, 381, 86, 20);
		panelProduct.add(txtTotalPriceWithVAT);
		
		txtTotalDiscount = new JTextField();
		txtTotalDiscount.setText("0");
		txtTotalDiscount.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				calculateTotals();
			}
		});
		txtTotalDiscount.setBounds(554, 325, 34, 20);
		panelProduct.add(txtTotalDiscount);
		txtTotalDiscount.setColumns(10);
		
		JLabel lblTotalDiscount2 = new JLabel("%");
		lblTotalDiscount2.setBounds(593, 328, 21, 14);
		panelProduct.add(lblTotalDiscount2);
		
		txtProductQuantity = new JTextField();
		txtProductQuantity.setColumns(10);
		txtProductQuantity.setBounds(106, 64, 46, 20);
		panelProduct.add(txtProductQuantity);
		
		JLabel lblProductQuantity = new JLabel("Antal");
		lblProductQuantity.setHorizontalAlignment(SwingConstants.LEFT);
		lblProductQuantity.setBounds(106, 45, 121, 14);
		panelProduct.add(lblProductQuantity);
		
		JLabel lblProductNo = new JLabel("Varenummer");
		lblProductNo.setBounds(10, 45, 86, 14);
		panelProduct.add(lblProductNo);
		
		txtProductNo = new JTextField();
		txtProductNo.setColumns(10);
		txtProductNo.setBounds(10, 64, 86, 20);
		panelProduct.add(txtProductNo);
		
		JButton btnCancelOrder = new JButton("Afbryd ordre");
		btnCancelOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnCancelOrder.setBounds(254, 607, 121, 43);
		contentPane.add(btnCancelOrder);
		
		JButton btnCreateOrder = new JButton("Opret ordre");
		btnCreateOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				endOrder();
			}
		});
		btnCreateOrder.setBounds(853, 607, 121, 43);
		contentPane.add(btnCreateOrder);
	}

	private void endOrder() {		
		if (order.getCustomer() != null) {
			salesController.endOrder(order);
			this.setVisible(false);
		} else {
			JOptionPane.showMessageDialog(this,
				    "Der er ikke tilknyttet en kunde til ordren.\nKan ikke oprette ordren!",
				    "Advarsel",
				    JOptionPane.WARNING_MESSAGE);
		}
	}

	private void calculateTotals() {
		double total = order.calculatePrice();
		double discountRate = 0;
		try {
			discountRate = Double.parseDouble(txtTotalDiscount.getText());
		}
		catch (Exception e) {
		}
		if(discountRate > 20) {
			discountRate = 20;
		}
		if (discountRate == (int)discountRate) {
			txtTotalDiscount.setText(String.format("%d", (int)discountRate));
		} else {
			txtTotalDiscount.setText(String.format("%s", discountRate));	
		}
		discountRate = discountRate / 100;
		double discount = discountRate * total;
		double totalNoVat = total - discount;
		double totalVat = totalNoVat * 1.25;
	    
		txtTotalPrice.setText(String.format("%.2f", total));
		txtTotalDiscountPrice.setText(String.format("%.2f", discount));
		txtTotalPriceWithoutVAT.setText(String.format("%.2f", totalNoVat));
		txtTotalPriceWithVAT.setText(String.format("%.2f", totalVat));
	}
	private void addPartOrder() {
		int itemId = 0;
		try {
			itemId = Integer.parseInt(txtProductNo.getText());
		} catch (NumberFormatException e) {
			JOptionPane.showMessageDialog(this,
				    "Du skal angive et varenummer!",
				    "Advarsel",
				    JOptionPane.WARNING_MESSAGE);
			return;
		}
		
		int quantity = 0;
		try {
			quantity = Integer.parseInt(txtProductQuantity.getText());
		} catch (NumberFormatException e) {
			JOptionPane.showMessageDialog(this,
				    "Du skal angive et antal!",
				    "Advarsel",
				    JOptionPane.WARNING_MESSAGE);
			return;
		}
		
		PartOrder po = null;
		try {
			po = salesController.addPartOrder(order, itemId, quantity);
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this,
				    "Ukendt vare!\nKan ikke oprette delordre",
				    "Advarsel",
				    JOptionPane.WARNING_MESSAGE);
			return;
		}

		String description = po.getItem().getName();
		double price = po.getItem().getSalesPrice();
		String colli = po.getItem().getDefaultColli();
		double lineTotal = quantity*price;
		
		PartOrderTableItem poti = new PartOrderTableItem(Integer.toString(itemId),description, String.format("%.2f", price), Integer.toString(quantity), colli, String.format("%.2f", lineTotal));
		tableModel.addRow(poti);
		tableModel.fireTableDataChanged();
		txtProductNo.setText("");
		txtProductQuantity.setText("");
		calculateTotals();
	}

	private void setOtherDeliveryAddressState() {
		lblFirstnameDelivery.setEnabled(chckbxOtherDeliveryAddress.isSelected());
		lblLastnameDelivery.setEnabled(chckbxOtherDeliveryAddress.isSelected());
		lblRoadDelivery.setEnabled(chckbxOtherDeliveryAddress.isSelected());
		lblHouseNoDelivery.setEnabled(chckbxOtherDeliveryAddress.isSelected());
		lblPostalcodeDelivery.setEnabled(chckbxOtherDeliveryAddress.isSelected());
		lblCityDelivery.setEnabled(chckbxOtherDeliveryAddress.isSelected());
		
		txtFirstnameDelivery.setEnabled(chckbxOtherDeliveryAddress.isSelected());
		txtLastnameDelivery.setEnabled(chckbxOtherDeliveryAddress.isSelected());
		txtRoadDelivery.setEnabled(chckbxOtherDeliveryAddress.isSelected());
		txtHouseNoDelivery.setEnabled(chckbxOtherDeliveryAddress.isSelected());
		txtPostalcodeDelivery.setEnabled(chckbxOtherDeliveryAddress.isSelected());
		txtCityDelivery.setEnabled(chckbxOtherDeliveryAddress.isSelected());
	}

	private void saveCustomerChanges() {
		String address = txtRoad.getText() + " " + txtHouseNo.getText() + ", " + txtPostalcode.getText() + " " + txtCity.getText();
		String no = txtPhone.getText();
		String group = txtCustomerGroup.getText();
		String firstName = txtFirstName.getText();
		String lastName = txtLastName.getText();
		String company = txtCompany.getText();
		String cvr = txtCvrNo.getText();
		String phone = txtPhone.getName();
		String email = txtPhone.getName();
		if(order == null) {
			System.out.println("Null Order!");
			return;
		}
		
		salesController.createCustomer(order, no, group, firstName, lastName, company, cvr, address, phone, email);
	}
}
